/*
 * @Author: c
 * @Date: 2024-02-07 00:22:52
 * @LastEditTime: 2024-03-28 04:28:04
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\music\track\track.controller.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Body, Controller, Delete, Get, Param, ParseArrayPipe, ParseIntPipe, Post, Put, Query, Req } from '@nestjs/common';
import { SkipAuth } from 'src/core/system/auth/constants';
import { FavoriteForm, TrackForm } from './dto/create-track.dto';
import { TrackPageQuery } from './dto/search-tracklist.dto';
import { TrackService } from './track.service';

@Controller('track')
export class TrackController {

  constructor(private readonly trackService: TrackService) { }


  /**
  * 歌单-我收藏的歌单
  * @param pageDto 
  * @returns 
  */
  @Get("favorite")
  getFavorite(@Req() req, @Query() pageDto: TrackPageQuery) {
    return this.trackService.myfavorite(req.user, pageDto);
  }

  /**
    * 歌单-新增-我收藏的歌单
    * @param songForm 
    * @returns 
    */
  @Post("favorite")
  createFavorite(@Req() req, @Body() songForm: FavoriteForm) {
    return this.trackService.createfavorite(req.user, songForm);
  }

  /**
    * 歌单-删除-我收藏的歌单
    * @param songForm 
    * @returns 
    */
  @Delete("favorite")
  deletefavorite(@Req() req, @Body() songForm: FavoriteForm) {
    return this.trackService.deletefavorite(req.user, songForm);
  }

  /**
   * 歌单-分页查询
   * @param pageDto 
   * @returns 
   */
  @SkipAuth()
  @Get("page")
  getPage(@Req() req, @Query() pageDto: TrackPageQuery) {
    return this.trackService.page(req.user, pageDto);
  }

  /**
   * 歌单-新增
   * @param pageDto 
   * @returns 
   */
  @Post()
  saveTrack(@Body() trackForm: TrackForm) {
    return this.trackService.saveTrack(trackForm); //必须return 不然报错终止整个运行的进程
  }

  /**
  * 歌单-单条表单数据
  * @param typeCode 
  * @returns 
  */
  @SkipAuth()
  @Get(":id/form")
  getTrackFormData(@Req() req: any,
    @Param('id', ParseIntPipe) id
  ) {
    const user = req.user
    return this.trackService.getTrackFormData(user, id);
  }

  /**
   * 歌单-修改
   * @param trackForm 
   * @returns 
   */
  @Put(':trackId')
  async updateTrack(@Req() req, @Param('trackId', ParseIntPipe) trackId: number, @Body() trackForm: TrackForm) {
    const user = req.user;
    return await this.trackService.update(user, trackId, trackForm); //必须return 不然报错终止整个运行的进程
  }

  /**
   * 歌单-删除
   * @param id
   * @returns 
   */
  @Delete(':ids')
  remove(@Param('ids', ParseArrayPipe) ids: number[]) {
    return this.trackService.removeByIds(ids);
  }

}
